<!--
 * @Author: 瞿旺兴 18774621495@163.com
 * @Date: 2022-05-20 15:02:59
 * @LastEditors: 瞿旺兴 18774621495@163.com
 * @LastEditTime: 2022-06-08 17:39:43
 * @FilePath: \nien-vue3-admin\src\views\finance\receiverManame\reconciliationManagement\Receivable\staticsManage\generalSummary\inde.vue
 * @Description: 提单报表
-->
<template>
  <custom-container :config="config" />
  <detail-dialog ref="detailDialogRef" />
</template>

<script setup lang="ts">
import { ref, reactive, getCurrentInstance, computed, defineAsyncComponent } from 'vue'
import { ElButton } from 'element-plus'
import { DictDirection } from '@/store/modules/dicts'
import { getSummaries } from '@/utils'

const DetailDialog = defineAsyncComponent(() => import('./components/DetailDialog.vue'))
const detailDialogRef = ref(null)
const {
  appContext: {
    config: {
      globalProperties: { $download },
    },
  },
} = getCurrentInstance()

const queryParams = reactive({
  pageSize: 10,
  pageNum: 1,
  customerName: undefined,
  serialNo: undefined,
  ywymc: undefined,
  endDate: undefined,
  sszd: undefined,
  zdzt: undefined,
  qd: undefined,
})
const exportLoading = ref<boolean>(false)

const config = computed({
  get() {
    return {
      query: {
        fields: [
          {
            label: '提单号',
            prop: 'customerName',
          },
          {
            label: '船公司',
            prop: 'serialNo',
          },
          {
            type: 'select',
            label: '运输类型',
            prop: 'ywymc',
            option: {
              dictInfo: { dict: DictDirection.业务员 },
            },
          },
          {
            label: '柜号',
            prop: 'status',
          },
          {
            label: '装柜地点',
            prop: 'qd',
          },
          {
            type: 'date-picker',
            label: '时间范围',
            prop: 'endDate',
            option: {
              type: 'date',
            },
          },
        ],
        queryParams,
        formOption: {},
      },
      btns: [
        {
          title: '导出报表',
          type: 'primary',
          loading: exportLoading.value,
          onClick: (e) => {
            exportLoading.value = true
            const data = queryParams
            $download(
              'finance/seaAirTransportFinanceAccount/listExport', 
              data, 
              `空海运账单_${ new Date().getTime() }.xlsx`,
            )
            .finally(() => {
              exportLoading.value = false
            })
          },
        },
      ],
      table: {
        columns: [
          { label: '服务商', align: 'center', prop: 'endDate' },
          { label: '提单号', align: 'center', prop: 'customerCode' },
          { label: '柜型', align: 'center', prop: 'customerName' },
          { label: '船公司', align: 'center', prop: 'paidAmount' },
          { label: '柜号', align: 'center', prop: 'totalVotes' },
          { label: '装柜地点', align: 'center', prop: 'totalPiece' },
          { label: '总件数', align: 'center', prop: 'totalWeight' },
          { label: '总实重', align: 'center', prop: 'totalVolumeWeight' },
          { label: '总计费重', align: 'center', prop: 'totalChargeWeight' },
          { label: '总材积重(方)', align: 'center', prop: '' },
          { label: '提单应收', align: 'center', prop: '' },
          { label: 'ups运费($)', align: 'center', prop: 'status' },
          { label: '提单应付', align: 'center', prop: '' },
          { label: '预估利润', align: 'center', prop: '' },
          {
            label: '操作',
            align: 'center',
            width: '200',
            fixed: 'right',
            render(h, params) {
              const el = h(
                ElButton,
                {
                  type: 'primary',
                  text: true,
                  onClick: () => {
                    detailDialogRef.value.open(params.row)
                  },
                },
                {
                  default: () => '账单详情',
                },
              )
              return el
            },
          },
        ],
        event: {
          showSummary: true,
          summaryMethod: getSummaries(['receivingTotalWeight']),
        },
      },
      api: () => Promise.resolve({ code: 200, data: [{}] }),
    }
  },
  set(val) {
    return val
  },
})

</script>